#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define rep(Ii,Jj,Kk) for(int Ii=(Jj),Ii##_=(Kk);Ii<=Ii##_;Ii++)
#define per(Ii,Jj,Kk) for(int Ii=(Jj),Ii##_=(Kk);Ii>=Ii##_;Ii--)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long double db;
#define fir first
#define sec second
#define siz(Aa) ((int)(Aa).size())
#define all(Aa) (Aa).begin(),(Aa).end()
#define ckmx(Aa,Bb) (Aa=max(Aa,Bb))
#define ckmn(Aa,Bb) (Aa=min(Aa,Bb))
#define Fi(s) freopen(s,"r",stdin)
#define Fo(s) freopen(s,"w",stdout)
#define Fre(s) Fi(s".in"),Fo(s".out")
struct Qis{
	FILE *I;char B[65536],*p1=B,*p2=B;
	char gc(){return p1==p2&&(p2=(p1=B)+fread(B,1,65536,I),p1==p2)?EOF:*p1++;}
	Qis(FILE *I_):I(I_){}
	template<typename T>void read(T &x){x=0;T f=1;char ch=' ';for(;!isdigit(ch);f=ch=='-'?-1:1,ch=gc());for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=gc());x*=f;}
	template<typename T>Qis& operator>>(T& x){read(x);return *this;}
	Qis&operator>>(char& x){x=' ';for(;x<=' ';)x=gc();return *this;}
	Qis&operator>>(char *x){char c=' ';for(;c<=' ';c=gc());for(;c>' ';*(x++)=c,c=gc());*x=0;return *this;}
	Qis&operator>>(string &x){x="";char c=' ';for(;c<=' ';c=gc());for(;c>' ';x+=c,c=gc());return *this;}
}qin(stdin);
struct Qos{
	FILE *O;char B[65536],*p=B;
	void pc(char x){p-B<65536?*p++=x:(fwrite(B,p-B,1,O),p=B,*p++=x);}
	void flush(){fwrite(B,p-B,1,O);}
	Qos(FILE *O_):O(O_){} ~Qos(){flush();}
	template<typename T>void write(T x){if(x<0){pc('-');if(x<-9)write(-(x/10));pc(48-x%10);}else{if(x>9)write(x/10);pc(48+x%10);}}
	template<typename T>Qos& operator<<(T x){write(x);return *this;}
	Qos&operator<<(const char x){pc(x);return *this;}
	Qos&operator<<(const char *x){for(int i=0;x[i];++i)pc(x[i]);return *this;}
	Qos&operator<<(const string x){for(char c:x)pc(c);return *this;}
}qout(stdout);
#define cin qin
#define cout qout
const int N=1000010,C=20;
int n,sa[N],rk[N],le[N<<1],f[N];
char s[N],val[N];
struct dsu{
	int f[N<<1];
	inline int gf(int x){return x==f[x]?x:f[x]=gf(f[x]);}
	void mer(int x,int y){f[gf(x)]=gf(y);}
	void clear(){iota(f+1,f+1+(n<<1),1);}
}d[C+1],t;
inline int o(int x){return x>n?2*n+1-x:x;}
int e[N];
void work(){
	cin>>n;
	rep(i,1,n) cin>>sa[i],sa[i]++;
	rep(i,1,2*n-1) cin>>le[i];
	fill(rk+1,rk+1+n,0);
	rep(i,1,n) rk[sa[i]]=i;
	if(count(rk+1,rk+1+n,0)){cout<<"-1\n";return ;}
	rep(i,1,2*n-1){
		if((i^le[i])&1){cout<<"-1\n";return ;}
		if(le[i]>i || le[i]+i>2*n){cout<<"-1\n";return ;}
	}
	fill(e+1,e+1+n,0);
	rep(i,0,C) d[i].clear();
	rep(i,1,n) d[0].mer(i,2*n+1-i);
	rep(i,1,2*n-1){
		int l=((i-le[i])>>1)+1,r=(i+le[i])>>1;
		if(l<=r){
			int z=__lg(r-l+1);
			d[z].mer(l,2*n+1-r);
		}
		if(l>1 && r<n){
			if(rk[l-1]>rk[r+1]) ckmx(e[l-1],rk[r+1]);
			else ckmx(e[r+1],rk[l-1]);
		}
	}
	per(w,C,1){
		rep(i,1,n-(1<<w)+1){
			int j=d[w].gf(i);
			d[w-1].mer(i,j);
			d[w-1].mer(i+(1<<(w-1)),j+(1<<(w-1)));
		}
	}
	t.clear();
	rep(i,1,2*n) t.mer(o(i),o(d[0].gf(i)));
	rep(i,1,n) f[i]=t.gf(i);
	// rep(i,1,n) cout<<f[i]<<" \n"[i==i_];
	rk[n+1]=0;
	fill(val+1,val+1+n,0);
	fill(s+1,s+1+n,'*');
	s[n+1]=0;
	val[f[sa[1]]]=s[sa[1]]='a';
	rep(i,2,n){
		// cout<<(s+1)<<"\n";
		int x=sa[i-1],y=sa[i];
		if(rk[x+1]<rk[y+1]){// <=
			s[y]=s[x];
		}else{// <
			s[y]=s[x]+1;
		}
		if(e[y] && s[y]==s[sa[e[y]]]) s[y]++;
		if(s[y]>'z' || (val[f[y]] && val[f[y]]!=s[y])){cout<<"-1\n";return ;}
		val[f[y]]=s[y];
	}
	rep(i,1,n) cout<<s[i];
	cout<<"\n";
}
signed main(){ios::sync_with_stdio(false);
	Fre("string");
	int T;cin>>T;
	while(T--)work();
return 0;}
/*
qio!!!
*/